<?php

namespace App\Http\Middleware;

use Closure;
use Auth;

class AdminAuthentication
{
    /**
     * Handle an incoming request.
     *
     * @param  \Illuminate\Http\Request  $request
     * @param  \Closure  $next
     * @return mixed
     */
    public function handle($request, Closure $next)
    {   
        // 必须将 admin/login 和 admin/postlogin 不设置验证，否则会无限循环
        if(Auth::check() || $request->is('admin/login') || $request->is('admin/postlogin')){
            return $next($request);
        }else{
            return redirect('/admin/login');
        }
        
    }
}
